package com.micro.boot.config;

import javax.sql.DataSource;

import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;

/**
 * @Title:
 *         <P>
 * 		MultipleDbConfig.java
 *         </P>
 * @Package
 *          <P>
 * 			com.micro.boot.config
 *          </P>
 * @Description:
 *               <P>
 * 				两个数据源配置
 *               </P>
 * @author renweiping
 * @date 2018年9月21日 下午5:33:30
 * @version 1.0
 */
//@Configuration
//@PropertySource("classpath:multipleDb.properties")
public class MultipleDbConfig {
	@Bean
	@Primary
	@ConfigurationProperties("multiple.datasource.first")
	public DataSourceProperties firstDataSourceProperties() {
		return new DataSourceProperties();
	}

	@Bean
	@Primary
	@ConfigurationProperties("multiple.datasource.first")
	public DataSource firstDataSource() {
		return firstDataSourceProperties().initializeDataSourceBuilder().build();
	}

	@Bean
	@ConfigurationProperties("multiple.datasource.second")
	public DataSourceProperties secondDataSourceProperties() {
		return new DataSourceProperties();
	}

	@Bean
	@ConfigurationProperties("multiple.datasource.second")
	public DataSource secondDataSource() {
		return secondDataSourceProperties().initializeDataSourceBuilder().build();
	}
}
